|
|
|
|
|
|
|
You can also map the BackColor, ForeColor, and BorderStyle properties to the corresponding properties of the UserControl object, if you want. |
|
|
|
|
|
|
|
|
5. Click Finish, and the wizard creates additional source code in your UserControl object. |
|
|
|
|
|
|
|
|
Now all you have to do is write the program code for the properties, methods, and events. |
|
|
|
|
|
|
|
|
Setting Up the Operation Property |
|
|
|
|
|
|
|
|
By default, the ActiveX Control Interface Wizard creates the Operation property as a Variant and includes a private variable m_Operation to hold the property's value. However, you will use an integer value to represent the operation: 0 for addition, 1 for multiplication, 2 for subtraction, and 3 for division. |
|
|
|
|
|
|
|
|
To make the control easy to use, you shouldn't require the users to memorize these arbitrary integer values. Therefore, you can use an Enum to provide the integer values. To allow your control to provide these values, you must first add the Enum declaration to the General Declarations section of the UserControl object, as shown in Listing 15.1. |
|
|
|
|
|
|
|
|
Listing 15.1 CALC.ZIPDeclaring an Enum for the Operation Property |
|
|
|
|
|
|
|
|
Public Enum OpType
Add = 0
Multiply = 1
Subtract = 2
Divide = 3
End Enum
Dim m_Operation As OpType <--- Change this line |
|
|
|
|
|
|
|
|
In Listing 15.1, you add a new type, OpType, as well as change the type of the m_Operation variable from Variant to OpType. Next, you need to modify the Operation Property's Get and Let procedures, as shown in Listing 15.2. |
|
|
|
|
|
|
|
|
Listing 15.2 CALC.ZIPChanging the Property Procedures to Use the OpType Type |
|
|
|
|
|
|
|
|
Public Property Get Operation() As OpType
Operation = m_Operation
End Property
Public Property Let Operation(ByVal New_Operation As OpType)
m_Operation = New_Operation
PropertyChanged "Operation"
Select Case m_Operation
Case Add
lblOperation = "+"
Case Subtract
lblOperation = "-" |
|
|
|
|
|